﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace admin.cyt369.com.Models.Orgs
{
    public class OrgDepartmentUserTree : Admin.CYT369.Com.DAL.Domains.Department
    {
        public OrgDepartmentUserTree(Admin.CYT369.Com.DAL.Domains.Department department)
        {
            this.NodeType = "DEPT";
            this.Id = department.Id;
            this.ParentID = department.ParentID;
            this.Code = department.Code;
            this.FullName = department.FullName;
            this.ShortName = department.ShortName;
            this.OrgID = department.OrgID;
            this.Enable = department.Enable;
            this.Latitude = department.Latitude;
            this.Longitude = department.Longitude;
            this.PhoneNumber = department.PhoneNumber;
            this.Email = department.Email;
            this.Address = department.Address;
            this.DepartmentType = department.DepartmentType;
        }

        public OrgDepartmentUserTree(Admin.CYT369.Com.DAL.Domains.Organization organization)
        {
            this.NodeType = "ORG";
            this.Id = organization.Id * OrgTreeConvert.ConvertVal;
            this.OrgID = organization.Id* OrgTreeConvert.ConvertVal;
            this.FullName = organization.FullName;
            this.ShortName = organization.ShortName;
            this.Address = organization.Address;
            this.Email = organization.Email;
            this.PhoneNumber = organization.PhoneNumber;
            this.PostCode = organization.PostCode;
            this.Latitude = organization.Latitude;
            this.Longitude = organization.Longitude;
        }

        public OrgDepartmentUserTree(Admin.CYT369.Com.DAL.Domains.SysUser user)
        {
            this.NodeType = "USR";
            this.Id = user.Id;
            this.FullName = user.FullName;
            this.ShortName = user.UserName;
            this.Address = user.Address;
            this.Email = user.Email;
            this.PhoneNumber = user.PhoneNumber;
        }

        public int id {
            get {
                return this.Id;
            }
        }

        public int? parentId {
            get { return this.ParentID == 0 ? null : (int?)this.ParentID; }
            set { this.ParentID = value.HasValue ? value.Value : 0; }
        }

        public string text {
            get { return this.FullName; }
        }


        public string iconCls { get; set; }

        public string state { get; set; }

        public string NodeType { get; set; }

        public List<admin.cyt369.com.Models.Orgs.OrgDepartmentUserTree> children { get; set; }

    }
}
